﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BF
{
	public class BF_BulletBase
	{
		public string name;
		public double weight;
		public BF_Material impactMaterial;
		public V3D dimension;
		public double aerocoeff;
		public virtual double area
		{
			get
			{
				return 0;
			}
		}
		public V3D Drag(V3D Vel)
		{
			double ro = 1.2754;
			return Vel.Unit * (-0.5 * ro * Vel.LengthSq * aerocoeff * area);
		}
		public BF_BulletBase(string n, double w, V3D dim, double a)
		{
			name = n;
			weight = w;
			dimension = dim;
			aerocoeff = a;
		}
	}
	public class BF_GunBullet : BF_BulletBase
	{
		public double diameter;
		public BF_GunBullet(string n, double w, V3D dim, double a, double d)
			: base(n, w, dim, a)
		{
		}
		public override double area
		{
			get
			{
				return diameter * diameter / 4 * Math.PI;
			}
		}
	}
	public delegate void OnImpact(BF_Bullet sender);
	public class BF_Bullet
	{
		public BF_Unit Owner;
		public BF_BulletState State;
		public BF_BulletBase Base;
		public V3D Position;
		public V3D Velocity;
		public BF_Bullet(BF_BulletBase _base)
		{
			Base = _base;
			State = BF_BulletState.Fired;
		}

		public void Process(double dt)
		{
			Velocity -= V3D.Green * 9.81 * dt;
			Position += Velocity * dt;
		}
		public V3D NextPos(double dt)
		{
			return Position + (Velocity - V3D.Green * 9.81 * dt) * dt;
		}
	}
}